package com.stx.bms.web;

import com.stx.bms.util.FileUploadUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/uploadImgTest")
@MultipartConfig
public class UploadTestServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String accessPath =
                FileUploadUtil.uploadFile(request, "myFile");

        //已经保存到数据库
        request.setAttribute("imgUrl", accessPath);

        System.out.println("accessPath = " + accessPath);

        request.getRequestDispatcher("index.jsp").forward(request, response);

    }

}
